package com.generalbackend.common.dingtalk.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * @author tim.xie
 * @date 2021/12/24 17:37
 */
@Data
public class ActionCard {
    private ActionCard() {}
    /**
     * 首屏会话透出的展示内容
     */
    private String title;
    /**
     * markdown格式的消息
     */
    private String text;
    /**
     * 0：按钮竖直排列
     * 1：按钮横向排列
     */
    private String btnOrientation;
    /**
     * 单个按钮的标题
     */
    private String singleTitle;
    /**
     * 点击消息跳转的URL
     */
    private String singleURL;
    /**
     * 按钮
     */
    private List<Btns> btns;

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Builder
    public static class Btns {
        /**
         * 按钮标题
         */
        private String title;
        /**
         * 按钮跳转URL
         */
        private String actionUrl;
    }

    /**
     * 整体跳转
     * @param title
     * @param text
     * @param btnOrientation
     * @param singleTitle
     * @param singleURL
     * @return
     */
    public static ActionCard buildOverallJumpActionCard(String title, String text, String btnOrientation, String singleTitle, String singleURL) {
        ActionCard actionCard = new ActionCard();
        actionCard.setTitle(title);
        actionCard.setText(text);
        actionCard.setBtnOrientation(btnOrientation);
        actionCard.setSingleTitle(singleTitle);
        actionCard.setSingleURL(singleURL);
        return actionCard;
    }

    /**
     * 独立跳转
     * @param title
     * @param text
     * @param btnOrientation
     * @param btns
     * @return
     */
    public static ActionCard buildAloneJumpActionCard(String title, String text, String btnOrientation, List<Btns> btns) {
        ActionCard actionCard = new ActionCard();
        actionCard.setTitle(title);
        actionCard.setText(text);
        actionCard.setBtnOrientation(btnOrientation);
        actionCard.setBtns(btns);
        return actionCard;
    }
}
